# 功能要求

# 1.
# 新会员注册
#
# 会员包含超级管理员和普通会员

# user_info.txt文件中默认包含
# amdin
# 用户，admin为超级管理员
#
# 新注册的都为为普通用户， 为超级管理员用户
#
# 管理员可以禁用普通用户。禁用后普通用户登录会提示账户被冻结
#
# 2.
# 会员登录
#
# 管理员登录后显示图书管理菜单。可以添加图书、修改图书、下架图书；
#
# 图书包含图书名称、图书单价、图书总数、书架剩余库存。
#
# 下架图书并不直接删除而是标记为不显示
#
# 普通会员只能借阅图书
#
# 3.
# 密码找回
# 4.
# 退出系统

data = (("注册", 0), ("登录", 1), ("会员充值", 2), ("注册登录", 3))
data1 = (("借书", 0), ("还书", 1), ("查询", 2))
borrow = []
# a = open("./db/user.text", "r")
# vip = a.readlines()
# a.close()
#
# kongzhi = False
# for x in vip:
#     name1 = x.split("|")[0]
#     admin = "admin"
#     if name1 != admin:
#         kongzhi = True
#
#
# if kongzhi:
#     f = open("./db/user.text", "a")
#     f.write("admin" + "|" + "123456" + "|" + "0" + "\n")
#     f.close()


for obj in data:
    print("{}:{}".format(obj[0], obj[1]))


def enroll():
    user = input("请输入用户名字")
    pasword = input("请输入用户密码")
    f = open("./db/user.text", "r")
    users = f.readlines()
    f.close()

    unIsExist = True
    for x in users:
        userUn = x.split("|")[0]
        print(userUn)
        if userUn == user:
            unIsExist = False
            break

    if unIsExist:
        str1 = user + "|" + pasword + "|" + "1" + "\n"
        f = open("./db/user.text", "a")
        f.write(str1)
        f.close()

        print("注册成功")
    else:
        print("该用户已存在")


def logIn():
    user = input("请输入用户名字")
    pasword = input("请输入用户密码")
    borrow.append(user)
    f = open("./db/user.text", "r")
    users = f.readlines()
    f.close()

    login1 = False
    for x in users:
        userUn = x.split("|")[0]
        if user == userUn:
            login1 = True
            break

    login2 = False
    dict1 = {"vip": "1"}
    if login1:
        for x in users:
            userUn = x.split("|")[0]
            print(userUn)
            paswordUn = x.split("|")[1]
            print(paswordUn)
            vipUn = x.split("|")[2]
            print(vipUn)
            if userUn == user and paswordUn == pasword:
                dict1["vip"] = vipUn
                dict1["user"] = userUn
                dict1["pasword"] = paswordUn
                login2 = True
                break

    if login2:
        print("登录成功")

        for obj1 in data1:
            print("{},{}".format(obj1[0], obj1[1]))
            index1 = int(input("请选择服务"))
            if index1 == 0:
                lend()
            elif index1 == 1:
                pass
            elif index1 == 2:
                pass


def lend():
    book = str(input("请输入要借的书的名字"))
    d = open("./db/book.text", "r")
    books = d.readlines()
    d.close()



    dalao = True
    for x in books:
        letter = x.split("|")[1]
        if letter == book:
            print("你要借的书已经被借走了哈")
            dalao = False
            break


    if dalao:
        s = open("./db/book.text", "a")
        s.write(borrow[len(borrow) - 1] + "|" + book )
        s.close()








index = int(input("请输入办理业务的序号"))

if index == 0:
    enroll()
elif index == 1:
    logIn()
elif index == 2:
    pass
elif index == 3:
    pass
